<template>
  <div>
    <el-table :data="dataList" stripe style="width: 80%; margin-top: 40px">
      <el-table-column prop="name" label="系统模块名称" align="left"/>
      <el-table-column  label="操作" align="center" width="100%">
        <template slot-scope="{row}">
          <el-button @click="openList(row)" type="text" size="small">添加</el-button>
          <el-button @click="delList(row)"  type="text" size="mini">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    
    <!-- edit 活动管理数据 -->
    <section>
      <activity-manage ref="activityManage" :isShow.sync="dialog0.isShow0" @editActivity="editObj" @closeTemp="dialog0.isShow0 = false"></activity-manage>
    </section>

     <!-- edit 社区管理数据 -->
    <section>
      <community-manage ref="communityManage" :isShow1.sync="dialog1.isShow1" @editcommunity="editObj1" @closeTemp="dialog1.isShow1 = false"></community-manage>
    </section>

    <!-- dele 活动管理 展示 -->
    <section>
      <delActivityManage ref="delactivity" :isShow2.sync="dialog2.isShow2" @editActivity="editObj2" @closeTemp="dialog2.isShow2 = false"></delActivityManage>
    </section>

    <!-- dele 社区管理 展示  -->
    <section>
      <delCommunityManage ref="deleCommunityManage" :isShow3.sync="dialog3.isShow3" @editActivity="editObj3" @closeTemp="dialog3.isShow3 = false"></delCommunityManage>
    </section>
  </div>
</template>

<script>
import { resolve } from "url";
import { waitingTime } from "@/utils";
import sizeTemp from '@/components/draggableSize';
import activityManage from './edit/activityManage';
import communityManage from './edit/communityManage';
import delActivityManage from './dele/activityManage';
import delCommunityManage from './dele/communityManage';
import { thirdPartyPage_listAll, thirdPartyPage_save, thirdPartyPage_edit, thirdPartyPage_delete,} from "@/api/thirdPartyPage";
export default {
  props: {
    mydata: {
      type: Array,
      default(){}
    },
    },
  components: {activityManage, communityManage, delActivityManage, delCommunityManage, sizeTemp },
  data() {
    return {
      activeName: '0',
      dialogVisible: false,
      mydialog:{
        title: '',
      },
      loading: false,
      accordion: '1',
      thirdData: [],
      activeNames: '1',
      deptUserList: [],
      formData: { banner_path: ''},
      fullscreen: false,
      jump_type: 0,
      somFrom: {},
      loading: false,
      accordion: '1',
      activeNames: '1',
      dataList: [
        { name: "活动管理" },
        { name: "社区管理" },
      ],
      dialog0: {isShow0: false},
      dialog1: {isShow1: false},
      dialog2: {isShow2: false},
      dialog3: {isShow3: false},
      ishowAddLink:{aaa: false},
      deptUserList: [],
    };
  },
  methods: {
    addData(){
      this.activeName = '0';
      this.$refs["myfrom"].validate(valid =>{
        if(valid){
          if(this.mydialog.title == '添加链接'){
            this.saveObj();
          }else{
            this.editObj();
          }
        }else{
          return false;
        }
      });  
    },
     async openForm(e, row){
      if(e === "edit"){
         this.mydialog.title = "编辑链接"
         this.dialogVisible = true;
         this.formData = row;
      }else{
         this.mydialog.title = '添加链接';
         this.dialogVisible = true;
         
      }
    },

      //添加第三方链接
     async saveObj(){
      if(this.formData ===''){
        this.$message.wraning('表单不能为空！');
        return 
      }else{
        const pramt  = {
          ...this.formData, company_id: localStorage.getItem("companyId") - 0,
          pageSet_id: sessionStorage.getItem("pageSetRow_Id") - 0,
          organization_id: sessionStorage.getItem("organization_id") - 0, 
        };
        let {data} = await thirdPartyPage_save(pramt);
        if(data.status == 100){
         this.$message.success('添加成功!');
         this.dialogVisible = false;
         this.thirdGetData();
         //清空表单
         this.formData = {};
        }else{
          this.$message.wraning('添加失败!');
        }
      }
    },

     //编辑第三方链接
     async editObj(){
      if(this.formData ===''){
        this.$message.wraning('表单不能为空！');
        return 
      }else{
        const pramt  = {
          ...this.formData, company_id: localStorage.getItem("companyId") - 0,
          pageSet_id: sessionStorage.getItem("pageSetRow_Id") - 0,
          organization_id: sessionStorage.getItem("organization_id") - 0,  
        };
        let {data} = await thirdPartyPage_edit(pramt);
        if(data.status == 100){
         this.$message.success('添加成功!');
         this.dialogVisible = false;
         this.thirdGetData();
      }else{
        this.$message.wraning('添加失败!');
        }
      }
    },

    //删除第三方数据
    async deleThirdGetData(row){
      try {
        const res = await this.$confirm("确认删除吗？");
        if(res == 'confirm'){
          this.loading = true;
         const {data} = await thirdPartyPage_delete({id:row.id});
          if(data.status == 100){
            this.loading = false;
            this.$message.success("删除成功！");
          }
          this.thirdGetData();
        }
      } catch (error) {
        this.$message.warning('删除失败!');
      }
    },
    //第三方数据查询
    async thirdGetData(){
      console.log(this.mydata);
      this.activeName = '1';
        this.loading = true;
        let {data} = await thirdPartyPage_listAll({ 
          company_id: localStorage.getItem("companyId")-0,
          pageSet_id: sessionStorage.getItem("pageSetRow_Id") - 0,
          organization_id: sessionStorage.getItem("organization_id") - 0, 
          });
        if(data.status===100){
          this.thirdData = data.data.rows;
          this.loading = false;
        }
    },
    closeTemp(){
      this.dialogVisible = false;
    },
    sizeSet() {
      this.$refs.size.open();
    },

    closeAddLink(){
      this.ishowAddLink.aaa = false;
    },
    editObj(e){
      this.dialog0.isShow0 = true;
    },
     editObj1(e){
      this.dialog1.isShow1 = true;
    },
    editObj2(e){
      this.dialog2.isShow2 = true;
    },
    editObj3(e){
      this.dialog3.isShow3 = true;
    },

    //编辑打开
    async openList(row){
      if(row.name==="活动管理"){
        this.dialog0.isShow0 = true;
        await this.$refs['activityManage'].initList();
      }

      if(row.name==="社区管理"){
        this.dialog1.isShow1 = true;
        await this.$refs['communityManage'].initList();
      }
    },

    //删除打开
    async delList(row){
      if(row.name==="活动管理"){
        this.dialog2.isShow2 = true;
        await this.$refs['delactivity'].initList();
      }
      
      if(row.name==="社区管理"){
        this.dialog3.isShow3 = true;
        await this.$refs['deleCommunityManage'].initList();
      }
    }
  },
  created(){
    // this.thirdGetData();
  }
};
</script>

<style lang="scss" scoped>
$border: 1px dashed #d9d9d9;
$picture-size: 120px;
.avatar-uploader {
  .el-upload {
    border: $border;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    &:hover {
      border-color: #409eff;
    }
  }
}

.avatar-uploader-icon {
  border: $border;
  font-size: 28px;
  color: #8c939d;
  width: $picture-size;
  height: $picture-size;
  line-height: $picture-size;
  text-align: center;
  border-radius: 5px;
  cursor: pointer;
}

.avatar {
  height: 70px;
  width: 70px;
  border-radius: 50%;
  // width: 60%;
  display: block;
  cursor: pointer;
}
.table-img {
    width: 150px;
    border-radius: 3px;
}
</style>
